package com.demo.blog;

import com.demo.common.model.Person;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * @author liliang
 * @description:
 * @date 2018/6/4.
 */
public class PersonValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        validateRequiredString("person.name","errorMsg", "请输入名称");
        validateRequiredString("person.age","errorMsg", "请输入年龄");
        Integer age = controller.getParaToInt("person.age");
        if (age > 120 || age <= 0) {
            addError("errorMsg"," 年龄范围不正确");
        }
    }

    @Override
    protected void handleError(Controller controller) {
        controller.renderJson();
    }
}
